package com.example.bilibili.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
import com.example.bilibili.domain.*;
import com.example.bilibili.mapper.BiliVideoMapper;
import com.example.bilibili.service.BiliVideoService;
import com.example.bilibili.util.NonStaticResourceHttpRequestHandler;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

@RestController
@AllArgsConstructor
public class FileRestController {

    private final NonStaticResourceHttpRequestHandler nonStaticResourceHttpRequestHandler;
    @Autowired
    private BiliVideoService biliVideoService;
    @Autowired
    private BiliVideoMapper biliVideoMapper;
    @Autowired
    private BiliVideo biliVideo;

    @RequestMapping("/findvideo")
    public Object findpath(String videoid){
        QueryWrapper<BiliVideo> qw1= new QueryWrapper<>();
        qw1.select("videoPath");
        qw1.eq("videoId",videoid);
        BiliVideo vid = biliVideoService.getOne(qw1);
        biliVideo.setVideopath(null);
        biliVideo.setVideopath(vid.getVideopath());
        System.out.println(biliVideo.getVideopath());
        return vid.getVideopath();
    }


    @RequestMapping("/videocomment")
    public Object videoPreview2(String videoid) {
        List<commentvo> list = biliVideoMapper.getvideocomment(videoid);
        return JSON.toJSONString(list);
    }
    @RequestMapping("/getvideoinfo")
    public Object getvideoinfo(String videoid) {
     vidinfovo vid =biliVideoMapper.getvideoinfo(videoid);
        return JSON.toJSONString(vid);
    }

}
